import CryptoJS from 'crypto-js'; // 引用AES源码js
/**
 * 加密
 * @param word
 * @returns {*}
 */
function encrypt(word) {
  const key = CryptoJS.enc.Utf8.parse('abcdefgabcdefg12');
  const srcs = CryptoJS.enc.Utf8.parse(word);
  const encrypted = CryptoJS.AES.encrypt(srcs, key, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  });
  return encrypted.toString();
}

/**
 * 解密
 * @param word
 * @returns {*}
 */
function decrypt(word) {
  const key = CryptoJS.enc.Utf8.parse('abcdefgabcdefg12');
  const decrypt = CryptoJS.AES.decrypt(word, key, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  });
  return CryptoJS.enc.Utf8.stringify(decrypt).toString();
}
export default {
  encrypt,
  decrypt
};
